import {onUnmounted, ref} from "vue";
// let count = 0;
export function useDefer(maxCount = 100) {
  const count = ref(0);
  let reqId: number;
  function updateFrame(){
    count.value++;
    if(count.value >= maxCount){
      return
    }
    reqId = requestAnimationFrame(updateFrame); // 递归调用
  }
  updateFrame();
  onUnmounted(()=>{
    cancelAnimationFrame(reqId);
  })
  return function (n:number) {
    return count.value >= n;
  }
}